home *** CD-ROM | disk | FTP | other *** search
- /* strncmp.c From TC Bible page 289 Use strncmp to compare a specified number
- of characters of two strings to one another. The comparison is case
- sensitive.*/
-
-
- #include <stdio.h>
- #include <string.h>
- main()
- {
- int len, result;
- char str1[80], str2[80];
- printf("Enter a string: ");
- gets(str1);
- printf("Enter a string to compare with first: ");
- gets(str2);
- printf("How many characters to compare: ");
- scanf(" %d", &len);
- printf("Based on case sensitive comparison of the first %d characters\n",
- len);
- result = strncmp(str1, str2, len);
- if (result == 0)
- {
- printf("\"%s\" == \"%s\"\n", str1, str2);
- }
- if (result < 0)
- {
- printf("\"%s\" < \"%s\"\n", str1, str2);
- }
- if (result > 0)
- {
- printf("\"%s\" > \"%s\"\n", str1, str2);
- }
- }